var tpl = "my name is <%name%>. I am <%profile.age%> years old.";

var data = {
    name: "Krasimir",
    profile: {
        age: 29,
    }
};
// get value by path
function getValueByPath(obj, path) {
    path = path.split('.')
    return (function getValue (obj, path) {
        if (path.length === 1) {
            return obj[path[0]]
        } else {
            return getValue(obj[path.shift()], path)
        }
    })(obj, path)
}

function render (tpl, data) {
    var re = /<%([\w$.]+)?%>/g;
    while(match = re.exec(tpl)) {
        tpl = tpl.replace(match[0], getValueByPath(data, match[1]))
    }
    return tpl;
}

console.log(render(tpl, data))